<?php 
namespace Modules\AuthAdmin\Http\Controllers\v1;
use Illuminate\Http\Request;
use Modules\AuthAdmin\Http\Requests\CommonIdRequest;
use Modules\AuthAdmin\Http\Requests\CommonStatusRequest;
use Modules\AuthAdmin\Http\Requests\AuthGroupStoreRequest;
use Modules\AuthAdmin\Http\Requests\AuthGroupUpdateRequest;
use Modules\AuthAdmin\Http\Requests\AuthGroupAccessUpdateRequest;
use Modules\AuthAdmin\Models\AuthGroup as AuthGroupModel;
use Modules\AuthAdmin\Models\AuthRule as AuthRuleModel;
class AuthGroupController extends CommonController
{
	/**
	 * @name  权限组列表
	 * @method  GET	
	 * @param  page int 页码
	 * @param  pagesize int 每页条数
	 * @param  name string 权限组名称		
	 * @param  status int 状态:0=禁用,1=启用	
	 * @param  created_at string 创建时间	
	 * @param  updated_at string 更新时间	
	 * @return  JSON
	 */
    public function index(Request $request)
    {
		return (new AuthGroupModel())->list_data($request->all());
    }
	/**
	 * @name  添加
	 * @method  POST	
	 * @param  name string 权限组名称	
	 * @return  JSON
	 */
    public function store(AuthGroupStoreRequest $request)
    {
		$data = $request->all();
		return (new AuthGroupModel())->common_create(['name'=>$data['name']]);
    }
	/**
	 * @name  编辑页面
	 * @method  GET	
	 * @param  id int 权限组id	
	 * @return  JSON
	 */
    public function edit(CommonIdRequest $request)
    {	
		$AuthGroupModel = new AuthGroupModel();
		return $AuthGroupModel->api_success([
			'data'=>$AuthGroupModel->select('id','name')->find($request->get('id'))
		]);
    }
	/**
	 * @name  编辑提交
	 * @method  PUT	
	 * @param  name string 权限组名称	
	 * @return  JSON
	 */ 
    public function update(AuthGroupUpdateRequest $request)
    {
		$data = $request->all();
		return (new AuthGroupModel())->common_update($data['id'],['name'=>$data['name']]); 
    }
	/**
	 * @name  调整状态
	 * @method  PUT	
	 * @param  id int 权限组id
	 * @param  status int 状态（0或1）
	 * @return  JSON
	 */ 
    public function status(CommonStatusRequest $request)
    {
		$data = $request->all();
		return (new AuthGroupModel())->common_status_update($data['id'],['status'=>$data['status']]); 
    }
	/**
	 * @name  分配权限
	 * @method  GET	
	 * @param  id int 权限组id
	 * @return  JSON
	 */  
    public function access(CommonIdRequest $request)
    {
		return (new AuthRuleModel())->access($request->get('id'));
    }
	/**
	 * @name  分配权限提交
	 * @method  PUT	
	 * @param  id int 权限组id
	 * @param  rules string 选择的权限
	 * @return  JSON
	 */  
    public function access_update(AuthGroupAccessUpdateRequest $request)
    {
		$data = $request->all();
		return (new AuthGroupModel())->common_false_update($data['id'],['rules'=>$data['rules']],'配置成功！','配置失败！'); 
    }
	
	
	
	
	
	
	
	
}
